home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / gr / intuition.c < prev    next >
C/C++ Source or Header  |  1991-09-01  |  3KB  |  106 lines

  1. #include "intuition.h"
  2.  
  3. struct NewScreen NewScreen = {
  4.     0,0,        /* leftedge ,topedge */
  5.     640,400,    /* width, height */
  6.     4,          /* depth, 4=16 colors */
  7.     0,1,        /* detail color, blockpen color */
  8.     HIRES|INTERLACE,      /* viewmode */
  9.     CUSTOMSCREEN, /* screen type */
  10.     NULL,       /* font */
  11.     (UBYTE*)"Graphics", /* title */
  12.     NULL,       /* gadgets */
  13.     NULL,       /* bitmap */
  14. };
  15.  
  16. struct NewWindow NewWindow = {
  17.     0,0,
  18.     640,400,
  19.     0,1,
  20.     MENUPICK | CLOSEWINDOW,
  21.     WINDOWCLOSE | SMART_REFRESH | ACTIVATE,
  22.     NULL,NULL,(UBYTE*)"Graphics 1.0",
  23.     NULL,NULL,50,25,640,400,CUSTOMSCREEN,
  24. };
  25.  
  26. struct IntuitionBase *IntuitionBase;
  27. struct GfxBase *GfxBase;
  28. struct Screen *Screen;
  29. struct Window *Window;
  30. struct RastPort *RastPort;
  31. extern struct Menu Project_menu;
  32.  
  33. void close_all(void)
  34. {
  35.     if (Window) CloseWindow(Window);
  36.     if (Screen) CloseScreen(Screen);
  37.     if (GfxBase) CloseLibrary(GfxBase);
  38.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  39. }
  40.  
  41. void init_libs(void)
  42. {
  43.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
  44.     if (IntuitionBase == NULL) {
  45.         fprintf(stderr,"error opening intuition.library\n");
  46.         exit(25);
  47.     }
  48.     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0L);
  49.     if (GfxBase == NULL) {
  50.         fprintf(stderr,"error opening graphics.library\n");
  51.         close_all();
  52.         exit(25);
  53.     }
  54. }
  55.  
  56. void init_screen(void)
  57. {
  58.     Screen = (struct Screen *)OpenScreen(&NewScreen);
  59.     if (Screen == NULL) {
  60.         fprintf(stderr,"error opening screen\n");
  61.         close_all();
  62.         exit(25);
  63.     }
  64.     RastPort = &Screen->RastPort;
  65. }
  66.  
  67. void init_window(void)
  68. {
  69.     NewWindow.Screen = Screen;
  70.     Window = OpenWindow(&NewWindow);
  71.     if (Window == NULL) {
  72.         fprintf(stderr,"error opening window\n");
  73.         close_all();
  74.         exit(25);
  75.     }
  76.     SetMenuStrip(Window, &Project_menu);
  77. }
  78.  
  79. /* This function returns:
  80.     0 when the CLOSE gadget is hit,
  81.     1 when a menu item is picked
  82.     It can be easily extended to return gadgets, mouse xy, etc
  83. */
  84.  
  85. long handle_user(long *menu,long *item,long *sub)
  86. {
  87.     long rc,class,code;
  88.     struct IntuiMessage *message;
  89.  
  90.     Wait(1<<Window->UserPort->mp_SigBit);
  91.     message = (struct IntuiMessage *)GetMsg(Window->UserPort);
  92.     class = message->Class;
  93.     code = message->Code;
  94.     ReplyMsg((struct Message *)message);
  95.     switch (class) {
  96.         case CLOSEWINDOW: rc=0;break;
  97.         case MENUPICK: {
  98.             *menu = MENUNUM(code);
  99.             *item = ITEMNUM(code);
  100.             *sub = SUBNUM(code);
  101.             rc = 1;
  102.         }
  103.     }
  104.     return rc;
  105. }
  106.